#!/bin/bash
#Author:        rengyi yan
#Date Time:     2015-08-11 08:54:41
#Descriptions:  auto install tomcat server
#               and setting TOMCAT_HOME env variables
#

 RETVAL=0
 BASEURL=http://mirror.bit.edu.cn/apache/tomcat/tomcat
 TOMCAT_VERSION=0

 TOMCAT_INSTANCE1=/usr/local/tomcat1
 TOMCAT_INSTANCE2=/usr/local/tomcat2
 TOMCAT_INSTANCE1_PORT=8080
 TOMCAT_INSTANCE2_PORT=8081

#Step 1: download the tomcat server package
 read -p 'please input the tomcat version like x.y.z(6.0.44):  ' TOMCAT_VERSION
 MAIN_VERSION=`echo $TOMCAT_VERSION | cut -d'.' -f 1`
 URL=$BASEURL-$MAIN_VERSION/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz
 wget $URL

#Step 2: installed tomcat instance to the directory
 for i in 1 2
  do
    instance=` echo "/usr/local/tomcat"$i `
    tar xzvf apache-tomcat-$TOMCAT_VERSION.tar.gz -C /usr/local
    mv /usr/local/apache-tomcat-$TOMCAT_VERSION $instance  
  done
 
 rm -f apache-tomcat-$TOMCAT_VERSION.tar.gz


#Step 3: modified the server.xml configfile
##################################################################
# instance:  /usr/local/tomcat1/
# configfile:/usr/local/tomcat1/conf/server.xml
# using the default config:8005 8080 8009 8443
#
# instance:  /usr/local/tomcat2/
# configfile:/usr/local/tomcat2/conf/server.xml
# using the config: 9005 9080 9009 9443
##################################################################
 cp ../conf.d/tomcat1-server.xml  /usr/local/tomcat1/conf/server.xml
 cp ../conf.d/tomcat2-server.xml  /usr/local/tomcat2/conf/server.xml
